﻿using HR.IService;
using HR.Models;

namespace HR.Service
{
    public class EngageInterviewService : IEngageInterviewService
    {
        private readonly HRDBContext db;

        public EngageInterviewService(HRDBContext db)
        {
            this.db = db;
        }

        public Task<engage_interview> EngageInterviewRecord(short res_id)
        {
            return Task.Run(() =>
            {
                engage_interview? ei = db.engage_interviews.Where(ei => ei.resume_id == res_id).OrderByDescending(ei => ei.ein_id).FirstOrDefault();
                engage_interview td = new engage_interview();
                if (ei == null)
                {
                    td.interview_amount = 1;
                }
                else
                {
                    td = ei;
                }
                return td;
            });

        }
        //新增面试记录信息
        public Task<int> EngageInterviewAdd(engage_interview ei)
        {
            return Task.Run(() =>
            {
                db.engage_interviews.Add(ei);
                return db.SaveChanges();
            });
        }
    }
}
